
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Document</title>
  
  <link href="<?php echo base_url();?>/public/css/bootstrap.min.css" rel="stylesheet">
  <link href="<?php echo base_url();?>/public/css/bootstrap-theme.min.css" rel="stylesheet">
  <link href="<?php echo base_url();?>/public/css/style.css" rel="stylesheet">

    <script charset="utf-8" src="<?php echo base_url();?>/public/kindeditor/kindeditor-all-min.js"></script>
    <script charset="utf-8" src="<?php echo base_url();?>/public/kindeditor/lang/zh-CN.js"></script>
    <script type="text/javascript" src="<?php echo base_url();?>/public/js/jquery.min.js"></script>
    <script type="text/javascript" src="<?php echo base_url();?>/public/js/jquery.upload.js"></script>
    <script type="text/javascript">
      $(function(){
         $("#article_add").submit(function(){
           if ($("#biaoti").val() =='') {

           alert("标题不能为空！");
               return false;
           }
          if ($('select[name=catalog_id]').val() == 'no') {

            alert("请选择一个分类！");
               return false;
          }; 
        
         })
  })
</script>

</head>

<body>
    <div class="container">
      <div  class="row" >
	      <div class="page-header">
          <h1><?php echo $title  ?>文章</h1>
        </div>
        
        <div class="col-md-9 col-md-offset-1">
          <form method="POST" class="form-horizontal" action="" enctype="multipart/form-data" id="article_add" >
            <div class="form-group">
              <label class="col-sm-2 control-label"><b class="error">*</b>标题</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" name="title" value="<?php echo set_value('title',$article->title) ?>" >
                <?php echo form_error('title'); ?>
                </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label"><b class="error">*</b>所属分类</label>
              <div class="col-sm-10">
                <select class="form-control" name="catalog_id">
                  <option value="">请选择一个分类</option>
                 <?php  foreach ($catalogs as $tb) {?>
                   <option  <?php echo set_select('catalog_id',$tb->id,$tb->id==$article->catalog_id); ?>  value="<?php echo $tb->id ?>"><?php echo $tb->name ?></option>
                 <?php 
                 } ?>
                </select>
                <?php echo form_error('catalog_id'); ?>
              </div>
            </div>
            
            <div class="form-group">
               <label class="col-sm-2 control-label"><b class="error">*</b>图片</label>
              <div class="col-sm-5">
                <input type="text" class="form-control" id="tupian"  name="img" value="<?php echo set_value('img',$article->img) ?>" >
                <a id="upload" href="#">上传文件</a>
                <?php echo form_error('img'); ?>
                </div>
                <div class="col-sm-5" id="pieview">
                </div>
           </div>
            
            <div class="form-group">
               <label class="col-sm-2 control-label"><b class="error">*</b>描述</label>
              <div class="col-sm-10">
                <textarea class="form-control" rows="6" cols="30" name="desc"><?php echo set_value('desc',$article->desc) ?></textarea>
                 <?php echo form_error('desc'); ?>
              </div>

            </div>
           
            <div class="form-group">
               <label class="col-sm-2 control-label" ><b class="error">*</b>内容</label>
              <div class="col-sm-10">
                <textarea class="form-control" name="content" id="abc"><?php echo set_value('content',$article->content) ?> </textarea>
                  <?php echo form_error('content'); ?>
              </div>
            </div>
           
            <div class="form-group">
              <div class="col-md-10 col-md-offset-2">
             <button type="submit" class="btn btn-primary  btn-lg  btn-block">提交</button>
            </div>
           </div>
            
          <div class="form-group">
              <div class="col-md-10 col-md-offset-2">
             <a class="btn btn-primary btn-lg btn-block" href="<?php echo site_url('admin/article/index') ?>">返回</a>
            </div>
           </div>
         </form>
         
        </div>


    </div>
  </div> 
 </body>
<script>
    KindEditor.create('#abc');


  $("#upload").click(function(){
    $.upload({
        url: '<?php echo site_url("admin/util/upload")?>', 
        fileName: 'file', 
        dataType: 'text',
        onSend: function() {
                return true;
        },
        onComplate: function(data) {
            if(data.indexOf('upload')>=0){//判断data里是否有upload
               $("#tupian").val(data);
               $("#pieview").html('<img style="height:80px;" src="<?php echo base_url()?>'+data+'" />');
         
          }else{
              alert(data);
        }
         }
    });
  })
    
</script>

</html>